package src.Thirteen;

import javax.swing.*;
import java.awt.*;
import java.net.URL;

public class JButtonTest extends JFrame {

    public JButtonTest(){
        URL url = JButtonTest.class.getResource("1.jpg");
        Icon icon = new ImageIcon(url);
        setLayout(new GridLayout(3,2,5,5));
        Container c = getContentPane();
        for (int i = 0; i < 5; i++) {
            JButton j = new JButton("按钮"+i,icon);
            c.add(j);
            if(i % 2 == 0){
                j.setEnabled(false);
            }
        }
        JButton jButton = new JButton();
        jButton.setMaximumSize(new Dimension(90,30));
        jButton.setIcon(icon);
        jButton.setHideActionText(true);
        jButton.setToolTipText("图片按钮");
        jButton.setBorderPainted(false);
        c.add(jButton);
        setTitle("创建带文字与图片的按钮");
        setSize(350,150);
        setVisible(true);
        setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    }

    public static void main(String[] args) {
        new JButtonTest();
    }
}
